#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <malloc.h>
#include <zlib.h>
#include <bzlib.h>
#include <environment.h>
#include <asm/byteorder.h>

int do_tftp_up_kerner (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	char cmd_buf[200];

    printf("download Linux ...\n");
    strcpy(cmd_buf, "tftpboot 0x32000000 uImage");
    run_command(cmd_buf, 0);

    printf("erase kernel ...\n");
    strcpy(cmd_buf, "nand erase kernel");
    run_command(cmd_buf, 0);

    printf("write kernel ...\n");
    strcpy(cmd_buf, "nand write.jffs2 0x32000000  kernel $(filesize)");
    run_command(cmd_buf, 0);

    printf("Booting Linux ...\n");
    strcpy(cmd_buf, "nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0");
    run_command(cmd_buf, 0);

    int i = 0;
    printf("hello OK! argc = %d\n",argc);
    for(i=0;i<argc;i++)
    {
        printf("argv[%d] = %s\n", i, argv[i]);
    }
    return 0;
}

U_BOOT_CMD(
 	tftpk,	 CFG_MAXARGS,	1,	do_tftp_up_kerner,
 	"hello\n",
	"hello..........\n"
);
